import { _ } from "core-js";

function TypeCheck() {
  let value = arguments[0];
  if (value !== undefined) return true;
}
function getBrowserInterfaceSize() {
  var pageWidth = window.innerWidth;
  var pageHeight = window.innerHeight;

  if (typeof pageWidth != "number") {
      //在标准模式下面
      if (document.compatMode == "CSS1Compat" ) {
          pageWidth = document.documentElement.clientWidth;
          pageHeight = document.documentElement.clientHeight;
      } else {
          pageWidth = document.body.clientWidth;
          pageHeight = window.body.clientHeight;
      }
  }

  return {
      pageWidth: pageWidth,
      pageHeight: pageHeight
  }
}

export const commonUtils = {
  data() {
    return {
      Timer: null,
    };
  },
  methods: {
    __InitWrapper(ele,bottomOffset=0) {
      ele.style.height =
      getBrowserInterfaceSize().pageHeight -
        ele.offsetTop -bottomOffset+
        "px";
    },
    __BsRefresh(App, duration) {
      let parent = this.$parent;
      while (parent) {
        if (parent[App]) {
          this._TimeOutProxy(() => {
            parent[App].refresh();
          }, duration);
          break;
        } else {
          parent = parent.$parent;
        }
      }
    },
    __FilterDate() {
      let [_list, index, isCheck] = arguments;
      if (!TypeCheck(_list)) return;
      if(index!==-1){
          _list = _list.filter((Item) => {
              return Item.rateType === index;
            });
      }
      if (isCheck) {
        _list = _list.filter((Item) => {
          return Item.text.length > 0;
        });
      }
      return _list;
    },
    _TimeOutProxy(callBack, duratioon) {
      this.Timer && clearTimeout(this.Timer) && (this.Timer = null);
      this.Timer = setTimeout(() => {
        callBack();
      }, duratioon);
    },
  },
};
